package com.bsoft.exchange.controller.hospitalization;

import com.bsoft.exchange.domain.AdvancedPaymentListDomain;
import com.bsoft.exchange.domain.ElectronicProofDomain;
import com.bsoft.exchange.domain.HospitalizationRecordDomain;
import com.bsoft.exchange.domain.PrepareBalance;
import com.bsoft.exchange.pojo.*;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.HospitalizationAppointmentService;
import com.bsoft.exchange.service.HospitalizationCostService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 创建日期 : 2019/10/14
 * 创建人 : 赵太行
 * 住院费用
 */
@RestController
@RequestMapping(value = "hospitalization")
public class HospitalizationController {
    @Autowired
    HospitalizationCostService hospitalizationCostService;
    @Autowired
    HospitalizationAppointmentService hospitalizationAppointmentService;

    /**
     * 获取出院带药信息
     */
    @ApiOperation("查询住院记录")
    @ResponseBody
    @RequestMapping(value = "/listHospitalizationRecord",method = RequestMethod.POST ,produces = "application/json")
    public ResponseEntity listHospitalizationRecord(@RequestBody @Validated HospitalizationRecordPojo data){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse<List<HospitalizationRecordDomain>> dataResponse= hospitalizationCostService.getRecord(data);
        entity.setData(dataResponse.getData());
        entity.setCode(dataResponse.getCode());
        entity.setMessage(dataResponse.getMessage());
        return entity;
    }
    /**
     * 获取电子住院证信息
     */
    @ApiOperation("获取电子健康卡信息")
    @RequestMapping(value = "/electronicProof",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity<ElectronicProofDomain> electronicProof(@RequestBody @Validated CardPojo cardPojo){

        String organizationId=cardPojo.getOrganizationId();
        String cardType=cardPojo.getCardType();
        String cardNumber=cardPojo.getCardNumber();
        ResponseEntity<ElectronicProofDomain> entity=new ResponseEntity();
        BaseResponse<ElectronicProofDomain> data=hospitalizationAppointmentService.electronicProof(organizationId, cardType, cardNumber);
        entity.setMessage(data.getMessage());
        entity.setCode(data.getCode());
        entity.setData(data.getData());
        return entity;
    }
    /**
     * 提交预约住院信息
     */
    @ApiOperation("提交预约住院信息")
    @RequestMapping(value = "/submitAppointment",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity submit(@RequestBody @Validated HospitalizationAppointmentPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse=hospitalizationAppointmentService.appointmentSubmit(pojo);
        entity.setMessage(baseResponse.getMessage());
        entity.setCode(baseResponse.getCode());
        return entity;
    }
    /**
     * 确认预约
     */
//    @ApiOperation("确认预约")
//    @RequestMapping(value = "/confirmNotification",method = RequestMethod.POST,produces = "application/json")
//    public ResponseEntity cancel(@RequestBody ConfirmNotificationPojo cancelZYYYPojo){
//        ResponseEntity entity=new ResponseEntity();
//        BaseResponse baseResponse=hospitalizationAppointmentService.confirmNotification(cancelZYYYPojo);
//        entity.setCode(baseResponse.getCode());
//        entity.setMessage(baseResponse.getMessage());
//        return entity;
//    }
    /**
     * 取消预约
     */
    @ApiOperation("取消预约")
    @RequestMapping(value = "/cancelAppointment",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity cancel(@RequestBody @Validated AppointmentCancelPojo cancelZYYYPojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse=hospitalizationAppointmentService.appointmentCancel(cancelZYYYPojo);
        entity.setCode(baseResponse.getCode());
        entity.setMessage(baseResponse.getMessage());
        return entity;
    }
    /**
     * 获取住院预缴金记录
     */
    @ApiOperation("获取预缴金记录")
    @RequestMapping(value = "/listPaymentHistory",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity listPaymentHistory(@RequestBody @Validated AdvancedPaymentListPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse<List<AdvancedPaymentListDomain>> response=hospitalizationCostService.getAdvacedPaymentList(pojo);
        entity.setCode(response.getCode());
        entity.setMessage(response.getMessage());
        entity.setData(response.getData());
        return entity;
    }
    /**
     * 获取每日费用
     */
    @ApiOperation("获取每日费用详情")
    @ResponseBody
    @RequestMapping(value = "/listHospitalizationPaymentDate",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity listHospitalizationPaymentDate(@RequestBody @Validated HospitalizationPaymentDatePojo pojo){
        ResponseEntity entity=new ResponseEntity();
        pojo.setPatientId("16"); //测试数据
        BaseResponse baseResponse= hospitalizationCostService.getListHospitalizationPaymentDate(pojo);
        entity.setCode(baseResponse.getCode());
        entity.setMessage(baseResponse.getMessage());
        entity.setData(baseResponse.getData());
        return entity;
    }
    /**
     * 获取每日费用
     */
    @ApiOperation("获取住院总费用详情")
    @ResponseBody
    @RequestMapping(value = "/getCostAggregation",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity listHospitalizationPayment(@RequestBody @Validated CostAggregationPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse= hospitalizationCostService.getListHospitalizationPayment(pojo);
        entity.setCode(baseResponse.getCode());
        entity.setMessage(baseResponse.getMessage());
        entity.setData(baseResponse.getData());
        return entity;
    }
    /**
     * 预缴金确认
     */
    @ApiOperation("预缴金确认接口")
    @ResponseBody
    @RequestMapping(value = "/hospitalizationDeposit",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity hospitalizationDeposit(@RequestBody @Validated HospitalizationDepositPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        try {
            BaseResponse baseResponse = hospitalizationCostService.confrimYJJ(pojo);
            entity.setCode(baseResponse.getCode());
            entity.setMessage(baseResponse.getMessage());
            entity.setData(baseResponse.getData());
        } catch (Exception e) {
            e.printStackTrace();
            entity.setCode(Constant.errorTag);
            entity.setMessage("确认预缴金失败");
        }

        return entity;
    }
    
    /**
     * 获取出院预结算信息
     */
    @ApiOperation("获取出院预结算信息")
    @ResponseBody
    @RequestMapping(value = "/getInHospitalPrecalFee",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity getPrecalculatedFee(@RequestBody @Validated CostAggregationPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse;
        try {
        	baseResponse = hospitalizationCostService.getPrecalculatedFee(pojo,0);
            entity.setCode(baseResponse.getCode());
            entity.setMessage(baseResponse.getMessage());
            entity.setData(baseResponse.getData());
        } catch (Exception e) {
            e.printStackTrace();
            entity.setCode(Constant.errorTag);
            entity.setMessage("获取出院费用预结算信息失败");
        }

        return entity;
    }
    /**
     * 确认出院结算信息
     */
    @ApiOperation("确认出院结算信息")
    @ResponseBody
    @RequestMapping(value = "/paySettlement",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity paySettlement(@RequestBody @Validated PaySettlementPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse;

        try {
            baseResponse = hospitalizationCostService.submitPaySettlement(pojo);
            entity.setCode(baseResponse.getCode());
            entity.setMessage(baseResponse.getMessage());
            entity.setData(baseResponse.getData());
        } catch (Exception e) {
            e.printStackTrace();
            entity.setCode(Constant.errorTag);
            entity.setMessage("确认出院结算失败");
        }

        return entity;
    }
    /**
     * 获取出院费用信息
     */
    @ApiOperation("获取出院费用信息")
    @ResponseBody
    @RequestMapping(value = "/dischargeSettlementInfo",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity dischargeSettlementInfo(@RequestBody @Validated BasePojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse=hospitalizationCostService.getDischargeSettlementInfo(pojo);
        entity.setCode(baseResponse.getCode());
        entity.setMessage(baseResponse.getMessage());
        entity.setData(baseResponse.getData());
        return entity;
    }

    /**
     * 获取出院带药信息
     */
    @ApiOperation("获取出院带药信息")
    @ResponseBody
    @RequestMapping(value = "/getDischargeMedicationInformation",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity getDischargeMedicationInformation(@RequestBody @Validated AdvancedPaymentListPojo pojo){
        ResponseEntity entity=new ResponseEntity();
        BaseResponse baseResponse=hospitalizationCostService.getDischargeMedicationInformation(pojo);
        entity.setCode(baseResponse.getCode());
        entity.setMessage(baseResponse.getMessage());
        entity.setData(baseResponse.getData());
        return entity;
    }


    /**
     * 获取预缴费信息
     */
    @ApiOperation("获取预缴费信息")
    @RequestMapping(value = "/getBalance",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity getBalance(@RequestParam(value = "sfzh") String sfzh){
        ResponseEntity entity=new ResponseEntity();
        sfzh = "320981199511203970"; //测试数据
        BaseResponse<PrepareBalance> response=hospitalizationCostService.getBalance(sfzh);
        entity.setCode(response.getCode());
        entity.setMessage(response.getMessage());
        entity.setData(response.getData());
        return entity;
    }


}
